﻿using Gzh.Entity.Base;
using Gzh.Entity.Model.User;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gzh.Entity.Mapping.User
{
    /// <summary>
    /// ${table.comment}
    /// </summary>
    public class ${TableName}Map : EntityMapBase<${TableName}>
    {
      public override void Configure(EntityTypeBuilder<${TableName}> builder)
        {
          base.Configure(builder);
       <#list table.columns  as column>
       <#if column.columnKey=='true'>
           // Primary Key
           builder.HasKey(t => t.${column.columnName});
           // Properties
          // builder.Property(t => t.id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        <#elseif column.isRequired =='true' && column.columnType =='String'>
           builder.Property(t => t.${column.columnName})
               .IsRequired()
               .HasMaxLength(${column.columnSize});
        <#elseif column.columnType =='String' && column.isRequired =='false'>
           builder.Property(t => t.${column.columnName})
               .HasMaxLength(${column.columnSize});
        <#elseif column.isRequired =='true'&& column.columnType !='String'>
           builder.Property(t => t.${column.columnName})
               .IsRequired();
       </#if>
        </#list>

           // Table & Column Mappings
        <#list table.columns  as column>
           builder.Property(t => t.${column.columnName}).HasColumnName("${column.columnName}");
        </#list>
        }
    }
}
